package cn.iocoder.yudao.module.api.infrastructure.config.dto;

import cn.iocoder.yudao.framework.validation.Percent;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.Data;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * 用户配置信息 Response DTO
 *
 * @author 山野羡民
 */
@Validated
@Data
public class MemberConfigRespDTO {

    //=====积分=====

    @Schema(description = "积分抵扣开关")
    private boolean pointTradeDeductEnable;

    @Schema(description = "积分抵扣，单位：分。1 积分抵扣多少分钱")
    @PositiveOrZero
    private int pointTradeDeductUnitPrice;

    @Schema(description = "单次下单积分抵扣最大值")
    @PositiveOrZero
    private int pointTradeDeductMaxPoint;

    @Schema(description = "购物多少分钱赠送 1 积分")
    @PositiveOrZero
    private int pointTradeGiveUnitPoint;

    @Schema(description = "打折销售差价多少分钱赠送 1 积分")
    @PositiveOrZero
    private int pointTradeGiveUnitPointForSeller;

    //=====经验=====

    @Schema(description = "拉新送多少经验")
    @PositiveOrZero
    private int experienceInviteGiveExperience;

    //=====贡献值=====

    @Schema(description = "拉新送多少贡献值")
    @PositiveOrZero
    private int growthInviteGiveGrowth;

    //=====联盟豆=====

    @Schema(description = "商家入驻后赠送多少个冻结中的联盟豆")
    @PositiveOrZero
    private int giveCryptocurrencyFreezing;

    @Schema(description = "邀请一个新用户赠送多少个联盟豆")
    @PositiveOrZero
    private int inviteGiveCryptocurrency;

    @Schema(description = "联盟豆抵扣开关")
    private boolean cryptocurrencyTradeDeductEnable;

    @Schema(description = "联盟豆抵扣，单位：分。1 联盟豆抵扣多少分钱")
    @PositiveOrZero
    private int cryptocurrencyTradeDeductUnitPrice;

    @Schema(description = "联盟豆转换为收益豆说明")
    private String cryptocurrencyNotIncrementTips;

    @Schema(description = "联盟豆投入收益池的规则说明")
    private String cryptocurrencyIncrementTips;

    @Schema(description = "联盟豆投入收益池的投入预设值，至少 10 个，必须是整数倍")
    private List<Integer> cryptocurrencyIncrementPresetAmounts;

    @SuppressWarnings("unused")
    public List<Integer> getCryptocurrencyIncrementPresetAmounts() {
        if (cryptocurrencyIncrementPresetAmounts == null) {
            return List.of();
        }
        return cryptocurrencyIncrementPresetAmounts.stream().distinct().sorted().toList();
    }

    @Schema(description = "联盟豆投入收益池的增值百分比，如：30 表示投入 100 个增长 30 个")
    @Percent
    private double cryptocurrencyIncrementPercent;

    @Schema(description = "联盟豆投入收益池的签到天数，如：30天")
    @PositiveOrZero
    private int cryptocurrencyIncrementDays;

    @Schema(description = "联盟豆兑换现金百分比，如：80 表示 100 个联盟豆可转化为80分钱")
    @Percent
    private double cryptocurrencyToMoneyPercent;

    @Schema(description = "联盟豆兑换现金提示")
    private String cryptocurrencyToMoneyTips;

    @Schema(description = "收益豆转分红百分比，如：20 表示 100 个收益豆可转化为 20 个分红")
    @Percent
    private double cryptocurrencyToBonusPercent;

    @Schema(description = "收益豆转分红提示")
    private String cryptocurrencyToBonusTips;

    //=====分红=====

    @Schema(description = "分红转股权/公益勋章分比，如：5 表示 100 个分红可转化为 5 个股权/公益勋章")
    @Percent
    private double bonusToShareholdingPercent;

    @Schema(description = "分红转股权/公益勋章提示")
    private String bonusToShareholdingTips;

    @Schema(description = "分红兑换现金百分比，如：80 表示 100 个分红可转化为80分钱")
    @Percent
    private double bonusToMoneyPercent;

    @Schema(description = "分红兑换现金提示")
    private String bonusToMoneyTips;

    @Schema(description = "分红权开通天数")
    private Integer bonusBenefitDays;

    @Schema(description = "分红权开通费用，单位为分")
    private Integer bonusBenefitPrice;

    @Schema(description = "分红权开通说明")
    private String bonusBenefitTips;

    //=====股权/公益勋章=====

    @Schema(description = "股权/公益勋章初始发行价，单位为分")
    private int shareholdingInitialPrice;

    @Schema(description = "股权/公益勋章产出消费金百分比，如：1 表示 100 个股权/公益勋章每日产出 1 个消费金")
    @Percent
    private double shareholdingToInterestPercent;

    @Schema(description = "股权/公益勋章产出消费金提示")
    private String shareholdingToInterestTips;

    //=====消费金=====

    @Schema(description = "消费金兑换现金百分比，如：100 表示 100 个消费金可转化为100分钱")
    @Percent
    private double interestToMoneyPercent;

    @Schema(description = "消费金兑换现金提示")
    private String interestToMoneyTips;

    //=====其他=====

    @Schema(description = "手续金百分比，如：20 表示兑换现金 100 分钱需要 20 个手续金")
    @Percent
    private double handlingFeePercent;

    @JsonIgnore
    public boolean isPointDeductDisable() {
        return !Boolean.TRUE.equals(pointTradeDeductEnable)  // 积分功能是否启用
               || pointTradeDeductUnitPrice == 0; // 有没有配置 1 积分抵扣多少分钱
    }

    @JsonIgnore
    public boolean isCryptocurrencyDeductDisable() {
        return !Boolean.TRUE.equals(cryptocurrencyTradeDeductEnable)  // 联盟豆功能是否启用
               || cryptocurrencyTradeDeductUnitPrice == 0; // 有没有配置 1 联盟豆抵扣多少分钱
    }

}
